#!/usr/bin/env python
import sys
from astropy.io import fits
from skimage.measure import label

def get_largest_cluster(mask):
    segs = label(mask)
    seg, npix = np.unique(segs, return_counts=True)
    index = seg > 0
    if index.sum() > 0:
        npixs = npix[index]        
        npixs.sort()
        result = npixs[-1]
        #result = np.max(npix[index])
    else:
        result = 1
    return result
    
mask = fits.getdata(sys.argv[1])
get_largest_cluster(mask)
